package com.corecloud.controller.sys;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.corecloud.entity.SysAreaEntity;
import com.corecloud.entity.SysDeptEntity;
import com.corecloud.entity.SysUserEntity;
import com.corecloud.service.SysAreaService;
import com.corecloud.service.SysDeptService;
import com.corecloud.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.security.Principal;

/**
 * 用户个人中心相关
 */
@Controller
@RequestMapping("/center")
public class UserCenterController {

	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private SysAreaService sysAreaService;
	@Autowired
	private SysDeptService sysDeptService;


	/**
	 * 用户个人中心页
	 * 只获取当前登录用户信息并展示
	 * @param principal
	 * @return
	 */
	@RequestMapping("/index")
	public ModelAndView index(Principal principal){
		ModelAndView modelAndView = new ModelAndView("center/index");
		modelAndView.addObject("userInfo",sysUserService.selectOne(new QueryWrapper<SysUserEntity>().eq("user_name",principal.getName())));
		modelAndView.addObject("areaList",sysAreaService.selectList(new QueryWrapper<SysAreaEntity>()));
		modelAndView.addObject("deptList",sysDeptService.selectList(new QueryWrapper<SysDeptEntity>().eq("is_valid",1)));
		return modelAndView;
	}



}
